const getUrlData = require('./getUrlData');
const getRequestJsonData = require('./getRequestJsonData');
const fs = require('fs');

// 获取用户列表
let getUserList = async () => {
    let getUserJson = getRequestJsonData.getUserList();
    let res = await getUrlData.getUrlData('get_qipaiguan_agentroomallgameuserinfo', getUserJson);
    let userList = res.data;
    if (userList.querycount <= 0) return null;
    // 用户数据存储
    let formatUserList = userList.data.filter(item => {
        item = Object.assign(item, { formatUserName: "" });
        return item;
    });
    return formatUserList;
    // fs.writeFileSync('./datalist/userlist.json', JSON.stringify(formatUserList));
}

// 获取赛事统计列表
let getGameList = async (time) => {
    if(!time) return new Error('没填写时间哦');
    let getGameJson = getRequestJsonData.getGameList(time);
    let res = await getUrlData.getUrlData('get_dalianmeng_agentroomsetletinfo', getGameJson);
    let gameList = res.data;
    if (gameList.querycount <= 0) return null;
    return gameList.data;
    // fs.writeFileSync('./datalist/gamelist.json', JSON.stringify(gameList.data));
}

// 获取斗地主用户列表 2020.10.07
let getDdzUserList = async () => {
    let getUserJson = getRequestJsonData.getDdzUserList();
    let res = await getUrlData.getUrlData('get_qipaiguan_agentroomallgameuserinfo', getUserJson);
    let userList = res.data;
    if (userList.querycount <= 0) return null;
    // 用户数据存储
    let formatUserList = userList.data.filter(item => {
        item = Object.assign(item, { formatUserName: "" });
        return item;
    });
    return formatUserList;
    // fs.writeFileSync('./datalist/userlist.json', JSON.stringify(formatUserList));
}

// 获取斗地主赛事统计列表
let getDdzGameList = async (time) => {
    if(!time) return new Error('没填写时间哦');
    let getGameJson = getRequestJsonData.getDdzGameList(time);
    let res = await getUrlData.getUrlData('get_dalianmeng_agentroomsetletinfo', getGameJson);
    let gameList = res.data;
    if (gameList.querycount <= 0) return null;
    return gameList.data;
    // fs.writeFileSync('./datalist/gamelist.json', JSON.stringify(gameList.data));
}


module.exports = {
    getUserList,
    getGameList,
    getDdzUserList,
    getDdzGameList
}